import request from '@/utils/request'

export default class BaseRApi {
  constructor(module) {
    this.module = module
    this.request = request
  }

  absUrl(url = '') {
    if (url && !url.startsWith('/')) {
      url = '/' + url
    }
    return '/api/' + this.module + url
  }

  // 详情接口方法
  detail(id) {
    return request.get(this.absUrl(id + ''))
  }

  post(urlName, data) {
    return request.post(this.absUrl(urlName), data)
  }

  get(urlName, params) {
    return request.get(this.absUrl(urlName), {params})
  }

  list({current = 1, size = 10, ...filter} = {}) {
    return request.get(this.absUrl(), {
      params: {
        current,
        size,
        filter: encodeURIComponent(JSON.stringify(filter))
      }
    })
    // return this.get('list', data)
  }

  export({exportOption, filter}) {
    return request.post(this.absUrl('export'), {
      exportOption,
      filter: JSON.stringify(filter)
    })
  }
}

